package com.ruoyi.factory.apilog.controller;

/**
 * @ClassName ApiLogController
 * @Description: TODO
 * @Author LiuJiaji
 * @Date 2023/9/15 16:00
 **/

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.factory.apilog.domain.ApiLog;
import com.ruoyi.factory.apilog.service.IApiLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * api操作日志Controller
 *
 * @author factory
 * @date 2021-01-27
 */
@RestController
@RequestMapping("/factory/log")
public class ApiLogController extends BaseController {
    private String prefix = "factory/log";

    @Autowired
    private IApiLogService apiLogService;

    /**
     * 查询api操作日志列表
     */
    @PreAuthorize("@ss.hasPermi('factory:log:list')")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ApiLog apiLog) {
        startPage();
        List<ApiLog> list = apiLogService.selectApiLogList(apiLog);
        return getDataTable(list);
    }

    /**
     * 获取api操作日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('factory:log:query')")
    @GetMapping(value = "/query/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(apiLogService.selectApiLogById(id));
    }

    /**
     * 导出api操作日志列表
     */
    @PreAuthorize("@ss.hasPermi('factory:log:export')")
    @Log(title = "api操作日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ApiLog apiLog) {
        List<ApiLog> list = apiLogService.selectApiLogList(apiLog);
        ExcelUtil<ApiLog> util = new ExcelUtil<ApiLog>(ApiLog.class);
        return util.exportExcel(list, "log");
    }


    /**
     * 新增保存api操作日志
     */
    @PreAuthorize("@ss.hasPermi('factory:log:add')")
    @Log(title = "api操作日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ApiLog apiLog) {
        return toAjax(apiLogService.insertApiLog(apiLog));
    }

    /**
     * 修改保存api操作日志
     */
    @PreAuthorize("@ss.hasPermi('factory:log:edit')")
    @Log(title = "api操作日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ApiLog apiLog) {
        return toAjax(apiLogService.updateApiLog(apiLog));
    }

    /**
     * 删除api操作日志
     */
    @PreAuthorize("@ss.hasPermi('factory:log:remove')")
    @Log(title = "api操作日志", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(apiLogService.deleteApiLogByIds(ids));
    }
}
